package com.controller.lims;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.DateUtils;
import com.common.http.HttpResult;
import com.service.lims.LimsBroadcastsService;
import com.model.lims.LimsBroadcastsModel;

/**
 *
 */
@Controller("limsBroadcastsController")
@RequestMapping(value = "/api")
public class LimsBroadcastsController {
    static final Logger logger = LoggerFactory.getLogger(LimsBroadcastsController.class);

    @Autowired
    LimsBroadcastsService limsBroadcastsService;


    /**
     * 查询列表
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/selectList", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult selectList(@RequestParam Map<String, Object> map) {
        return limsBroadcastsService.selectList(map);
    }

    /**
     * 查询详情
     *
     * @param
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/selectInfor", method = {RequestMethod.GET})
    @ResponseBody
    public HttpResult selectInfor(@RequestParam String spId) {
        return limsBroadcastsService.selectInfor(spId);
    }

    /**
     * 保存
     *
     * @param
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/save", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult save(@RequestBody LimsBroadcastsModel limsBroadcastsModel) {
        return limsBroadcastsService.save(limsBroadcastsModel);
    }


    /**
     * 删除
     *
     * @param
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/delete", method = {RequestMethod.DELETE})
    @ResponseBody
    public HttpResult delete(@RequestParam String spId) {
        return limsBroadcastsService.delete(spId);
    }


    /**
     * 导出
     *
     * @param map
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "lims/broadcasts/export")
    public void export(@RequestParam Map<String, Object> map, HttpServletResponse response) throws IOException {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("采购订单-" + DateUtils.getCurrentDate(), "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        limsBroadcastsService.export(map, response);

    }

    /**
     * 查询当日接收后未提交的样品列表
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/getLimsNoCommitSamples", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult getLimsNoCommitSamples(@RequestBody Map<String, Object> map) {
        return limsBroadcastsService.getLimsNoCommitSamples(map);
    }

    /**
     * 超时未提交的样品播报次数+1，超七次后不再提醒
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/updateBroadcastNumBySamNo", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult updateBroadcastNumBySamNo(@RequestBody Map<String, Object> map) {
        return limsBroadcastsService.updateBroadcastNumBySamNo(map);
    }

    /**
     * 查询当日发布后未打印的样品列表
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/getLimsNoPrintCOASamples", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult getLimsNoPrintCOASamples(@RequestBody Map<String, Object> map) {
        return limsBroadcastsService.getLimsNoPrintCOASamples(map);
    }

    /**
     * 超时未提交的样品播报次数+1，超七次后不再提醒
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/updateNoPrintBroadcastNumBySamNo", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult updateNoPrintBroadcastNumBySamNo(@RequestBody Map<String, Object> map) {
        return limsBroadcastsService.updateNoPrintBroadcastNumBySamNo(map);
    }

    /**
     * 查询当日已提交的样品列表
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/getLimsCommitedSamples", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult getLimsCommitedSamples(@RequestBody Map<String, Object> map) {
        return limsBroadcastsService.getLimsCommitedSamples(map);
    }

    /**
     * 已提交播报次数+1，超3次后不再提醒
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "lims/broadcasts/updateCommitedNumBySamNo", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult updateCommitedNumBySamNo(@RequestBody Map<String, Object> map) {
        return limsBroadcastsService.updateCommitedNumBySamNo(map);
    }
}
